package top.ajunnihao.core.util.resp;

import org.springframework.http.HttpStatus;

/**
 * TODO 响应数据体
 *
 * @author AJun
 * @version 1.0.0
 * @date 2020/5/15
 */
public class JResp<T> extends BaseResp {

    /**
     * 响应数据
     */
    private T data;

    private JResp() {

    }

    private JResp(T data) {
        this.data = data;
    }

    private JResp(CodeEnum codeEnum) {
        super(codeEnum);
    }

    private JResp(CodeEnum codeEnum, T data) {
        super(codeEnum);
        this.data = data;
    }

    private JResp(CodeEnum codeEnum, String message, T data) {
        super(codeEnum, message);
        this.data = data;
    }

    private JResp(CodeEnum codeEnum, HttpStatus httpStatus, T data) {
        super(codeEnum, httpStatus);
        this.data = data;
    }

    private JResp(CodeEnum codeEnum, Integer statusCode, T data) {
        super(codeEnum, statusCode);
        this.data = data;
    }

    private JResp(CodeEnum codeEnum, HttpStatus httpStatus, String message, T data) {
        super(codeEnum, httpStatus, message);
        this.data = data;
    }

    private JResp(CodeEnum codeEnum, Integer statusCode, String message, T data) {
        super(codeEnum, statusCode, message);
        this.data = data;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    /**
     * 成功响应
     */
    public static BaseResp success() {
        return new BaseResp(CodeEnum.SUCCESS);
    }

    public static BaseResp success(String message) {
        return new BaseResp(CodeEnum.SUCCESS, message);
    }

    public static BaseResp success(HttpStatus httpStatus) {
        return new BaseResp(CodeEnum.SUCCESS, httpStatus);
    }

    public static BaseResp success(Integer statusCode) {
        return new BaseResp(CodeEnum.SUCCESS, statusCode);
    }

    public static BaseResp success(HttpStatus httpStatus, String message) {
        return new BaseResp(CodeEnum.SUCCESS, httpStatus, message);
    }

    public static BaseResp success(Integer statusCode, String message) {
        return new BaseResp(CodeEnum.SUCCESS, statusCode, message);
    }

    public static <T> JResp<T> success(T data) {
        return new JResp<T>(CodeEnum.SUCCESS, data);
    }

    public static <T> JResp<T> success(T data, String message) {
        return new JResp<T>(CodeEnum.SUCCESS, message, data);
    }

    public static <T> JResp<T> success(HttpStatus httpStatus, T data) {
        return new JResp<T>(CodeEnum.SUCCESS, httpStatus, data);
    }

    public static <T> JResp<T> success(Integer statusCode, T data) {
        return new JResp<T>(CodeEnum.SUCCESS, statusCode, data);
    }

    public static <T> JResp<T> success(HttpStatus httpStatus, T data, String message) {
        return new JResp<T>(CodeEnum.SUCCESS, httpStatus, message, data);
    }

    public static <T> JResp<T> success(Integer statusCode, T data, String message) {
        return new JResp<T>(CodeEnum.SUCCESS, statusCode, message, data);
    }

    /**
     * 失败响应
     */
    public static BaseResp fail() {
        return new BaseResp(CodeEnum.FAIL);
    }

    public static BaseResp fail(String message) {
        return new BaseResp(CodeEnum.FAIL, message);
    }

    public static BaseResp fail(HttpStatus httpStatus) {
        return new BaseResp(CodeEnum.FAIL, httpStatus);
    }

    public static BaseResp fail(Integer statusCode) {
        return new BaseResp(CodeEnum.FAIL, statusCode);
    }

    public static BaseResp fail(HttpStatus httpStatus, String message) {
        return new BaseResp(CodeEnum.FAIL, httpStatus, message);
    }

    public static BaseResp fail(Integer statusCode, String message) {
        return new BaseResp(CodeEnum.FAIL, statusCode, message);
    }

    public static <T> JResp<T> fail(T data) {
        return new JResp<T>(CodeEnum.FAIL, data);
    }

    public static <T> JResp<T> fail(T data, String message) {
        return new JResp<T>(CodeEnum.FAIL, message, data);
    }

    public static <T> JResp<T> fail(HttpStatus httpStatus, T data) {
        return new JResp<T>(CodeEnum.FAIL, httpStatus, data);
    }

    public static <T> JResp<T> fail(Integer statusCode, T data) {
        return new JResp<T>(CodeEnum.FAIL, statusCode, data);
    }

    public static <T> JResp<T> fail(HttpStatus httpStatus, T data, String message) {
        return new JResp<T>(CodeEnum.FAIL, httpStatus, message, data);
    }

    public static <T> JResp<T> fail(Integer statusCode, T data, String message) {
        return new JResp<T>(CodeEnum.FAIL, statusCode, message, data);
    }

    /**
     * 200 OK 响应
     */
    public static BaseResp ok() {
        return new BaseResp(CodeEnum.SUCCESS, HttpStatus.OK);
    }

    public static BaseResp ok(String message) {
        return new BaseResp(CodeEnum.SUCCESS, HttpStatus.OK, message);
    }

    public static <T> JResp<T> ok(T data) {
        return new JResp<T>(CodeEnum.SUCCESS, HttpStatus.OK, data);
    }

    public static <T> JResp<T> ok(T data, String message) {
        return new JResp<T>(CodeEnum.SUCCESS, HttpStatus.OK, message, data);
    }

    /**
     * 404 Not Found 响应
     */
    public static BaseResp notFound() {
        return new BaseResp(CodeEnum.FAIL, HttpStatus.NOT_FOUND);
    }

    public static BaseResp notFound(String message) {
        return new BaseResp(CodeEnum.FAIL, HttpStatus.NOT_FOUND, message);
    }

    public static <T> JResp<T> notFound(T data) {
        return new JResp<T>(CodeEnum.FAIL, HttpStatus.NOT_FOUND, data);
    }

    public static <T> JResp<T> notFound(T data, String message) {
        return new JResp<T>(CodeEnum.FAIL, HttpStatus.NOT_FOUND, message, data);
    }

    /**
     * 500 Internal Server Error 响应
     */
    public static BaseResp internalServerError() {
        return new BaseResp(CodeEnum.FAIL, HttpStatus.INTERNAL_SERVER_ERROR);
    }

    public static BaseResp internalServerError(String message) {
        return new BaseResp(CodeEnum.FAIL, HttpStatus.INTERNAL_SERVER_ERROR, message);
    }

    public static <T> JResp<T> internalServerError(T data) {
        return new JResp<T>(CodeEnum.FAIL, HttpStatus.INTERNAL_SERVER_ERROR, data);
    }

    public static <T> JResp<T> internalServerError(T data, String message) {
        return new JResp<T>(CodeEnum.FAIL, HttpStatus.INTERNAL_SERVER_ERROR, message, data);
    }

    @Override
    public String toString() {
        return "JResp{" +
                "data=" + data +
                "} " + super.toString();
    }

}
